package com.hongxun.budget.ui.fragment.ys;

import android.widget.TextView;

import com.hongxun.budget.R;
import com.hongxun.budget.greendao.EDeviceBuyEntityDao;
import com.hongxun.budget.ui.fragment.BaseListFragment;
import com.hongxun.budget.utils.DBUtils;
import com.hongxun.budget.utils.GreenDaoManager;
import com.hongxun.budget.utils.SPUtils;
import com.hongxun.greenentity.ys.EDeviceBuyEntity;
import com.jessewu.library.SuperAdapter;
import com.jessewu.library.view.ViewHolder;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by admin on 2018/8/17.
 */

public class YsDeviceBuyInfoFragment extends BaseListFragment {
    List<EDeviceBuyEntity> datas = new ArrayList<>();
    SuperAdapter<EDeviceBuyEntity> adapter;

    @Override
    public SuperAdapter getAdapter() {
        return adapter = new SuperAdapter<EDeviceBuyEntity>(R.layout.content_fragment_device_buy_info) {
            @Override
            public void bindView(ViewHolder viewHolder, EDeviceBuyEntity d, int i) {
                ((TextView) viewHolder.getView(R.id.lineName)).setText(DBUtils.getYsLineNameWithPPname(d.getPPGuid()));
                ((TextView) viewHolder.getView(R.id.price)).setText(d.getDBPriceall() + "元");
                ((TextView) viewHolder.getView(R.id.name)).setText(d.getDBName());
                ((TextView) viewHolder.getView(R.id.parameter)).setText(d.getDBParameter());
                ((TextView) viewHolder.getView(R.id.count)).setText(d.getDBCount() + "");
                ((TextView) viewHolder.getView(R.id.unit)).setText("(" + d.getDBUnit() + ")");
            }
        };
    }

    @Override
    public  void initView() {
        super.initView();
        datas.addAll(GreenDaoManager.getInstance().getmDaoSession().getEDeviceBuyEntityDao().queryBuilder().where(
                EDeviceBuyEntityDao.Properties.PGuid.eq(SPUtils.get(context, "project_ys_guid", ""))
                , EDeviceBuyEntityDao.Properties.DBDatastate.notEq("删除")
        ).list());
        adapter.setData(datas);
        adapter.setEmptyDataView(R.layout.view_empty);
    }
}
